package com.chif.mapreduce.ETL;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WebLogMapper extends Mapper<LongWritable, Text,Text, NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1 获取1行数据
        String line = value.toString();

        //2 解析日志
        boolean b = parseLog(line,context);


        //3 日志不合法瑞出
        if (!b){
            return;
        }

        //4 日志合法就写出
        context.write(value,NullWritable.get());
    }

    private boolean parseLog(String line,Context context){
        //1 截取
        String[] fields = line.split(" ");

        //2 日志长度大于11 的为合法
        if (fields.length>11){
            return true;
        }else {
            return false;
        }
    }


}
